import { AsyncStorage } from "react-native";

let Storage = {

}

Storage.setData = async (key,value) => {
    try {
      await AsyncStorage.setItem(key,value);
    } catch (error) {
      // Error saving data
    }
  }

Storage.getData = async (key) => {
    try {
      const value = await AsyncStorage.getItem(key);
      if (value !== null) {
        // We have data!!
        return value;
      }
     } catch (error) {
       // Error retrieving data
     }
  }

Storage.getAllKeys = async () => {
    try {
        const value = await AsyncStorage.getAllKeys();
        if (value !== null) {
            // We have data!!
            return value;
          }
     } catch (error) {
       // Error retrieving data
     }
  }

Storage.multiGet = async (keys) => {
    try {
        const value = await AsyncStorage.multiGet(keys);
        if (value !== null) {
            // We have data!!
            return value;
          }
     } catch (error) {
       // Error retrieving data
     }
  }

Storage.removeData = async (key) => {
    try {
      await AsyncStorage.removeItem(key);
    } catch (error) {
      // Error saving data
    }
  }


Storage.mergeData = async (key,value) => {
    try {
      await AsyncStorage.mergeItem(key,value);
    } catch (error) {
      // Error saving data
    }
  }

Storage.chunkArray = (data,segment)=>{
    let len = data.length;
    let ret=[];
    for (var i = 0; i <= len-1; i=i+segment) {
      ret.push(data.slice(i,i+segment))
    }
    return ret;
  }
  
export default Storage